﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for ThucDon
/// </summary>
public class ThucDon
{
	public ThucDon()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public DataTable GetAllFood()
    {
        DBconnect connet = new DBconnect();
        connet.Open();
        if (connet.IsConnected == false)
            return null;
        DataTable result = new DataTable();
        string sql = "SELECT T1.MenuId, T1.Name, T2.Quantity, T1.Cost, T2.Image, T2.Unit";
        sql += " FROM [OFSSDB].[dbo].Menu T1 ";
        sql += " LEFT JOIN [OFSSDB].[dbo].MenuDetail T2 ON T1.MenuId = T2.MenuId ";       
        result = connet.GetDataTable(sql);
        connet.Close();
        return result;
    }
   
    public DataTable AllMenu()
    {
        DBconnect DB = new DBconnect();
        DB.Open();
        DataTable Tmp = new DataTable();
        string query = "select * from MENU where isDelete = 0";        
        Tmp = DB.GetDataTable(query);
        
        DB.Close();
        return Tmp;
    }
    public DataTable AllMenuFavorite(string customerId)
    {
        DBconnect DB = new DBconnect();
        DB.Open();
        DataTable Tmp = new DataTable();
        string query = "select * from MenuFavorites T1, MENU T2 where T1.MenuId = T2.MenuId AND  T1.isDelete = 0 AND T2.IsDelete = 0 AND T1.CustomerId = " + customerId;        
        Tmp = DB.GetDataTable(query);
        
        DB.Close();
        return Tmp;
    }
    public int DeleteMenu(string ID)
    {
        DBconnect connect = new DBconnect();
        connect.Open();
        if (connect.IsConnected == false)
            return -1;
        string[] listcol = new string[] { "IsDelete" };
        object[] listobject = new object[] { "1" };
        int n = connect.Update("Menu", listcol, listobject, "MenuId=@ID", "@ID", ID);
        connect.Close();
        return n;
    }
    public Boolean CheckFoodExist(String MenuId, String FoodId)
    {
        DBconnect connect = new DBconnect();
        connect.Open();
        string query = "Select * from MenuDetail";
        query += " where MenuId='" + MenuId + "'";
        query += " and FoodId='" + FoodId + "'";
        DataTable DBTable = new DataTable();
        DBTable = connect.GetDataTable(query);
        if (DBTable.Rows.Count >= 0)
        {
            return true;
        }
        else
            return false;
        connect.Close();
    }

}
